package lsy.tools;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebFilter(urlPatterns = {"/*"})
public class PathFilter implements Filter {
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest httpServletRequest=(HttpServletRequest)request;
        HttpServletResponse httpServletResponse=(HttpServletResponse)response;
        String path=httpServletRequest.getContextPath();
        String basePath=httpServletRequest.getScheme() +"://"+httpServletRequest.getServerName() +":" +httpServletRequest.getServerPort() +path+"/";
        httpServletRequest.setAttribute("basePath",basePath);
        chain.doFilter(httpServletRequest,httpServletResponse);
    }
}
